<template>
  <div align="center">
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item label="输入关键字：">
        <el-input v-model="keyWord" placeholder="tel/name"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="selConditionVehicle()"
          >查询</el-button
        >
      </el-form-item>
    </el-form>
    <el-table
      :data="vehicleList.list"
      border
      align="center"
      style="width: 70%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="expand">
        <template slot-scope="props" align="center">
          <el-form
            align="center"
            label-position="left"
            inline
            class="demo-table-expand"
          >
            <el-form-item label="车位ID">
              <span>{{ props.row.vehicle_id }}</span>
            </el-form-item>
            <el-form-item label="车牌号">
              <span>{{ props.row.vehicle_code }}</span>
            </el-form-item>
            <el-form-item label="车辆拥有者">
              <span>{{ props.row.users.user_name }}</span>
            </el-form-item>
            <el-form-item label="车辆规格">
              <span>{{ props.row.vehicle_size }}</span>
            </el-form-item>
            <el-form-item label="车辆颜色">
              <span>{{ props.row.vehicle_color }}</span>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>
      <el-table-column type="selection" width="55" prop="Vehicle_id">
      </el-table-column>
      <el-table-column label="车辆照片" align="center">
        <template slot-scope="scope">
            <el-image
              style="width: 100px; height: 100px"
              :src="scope.row.vehicle_photo"
            >
            </el-image>
          
        </template> 
      </el-table-column>
      <el-table-column label="车牌号" prop="vehicle_code" sortable>
      </el-table-column>
      <el-table-column label="车辆所有者" prop="users.user_name">
      </el-table-column>
    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="vehicleList.pageNum"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="5"
      layout="total, sizes, prev, pager, next, jumper"
      :total="vehicleList.total"
    >
    </el-pagination>
  </div>
</template>

<style>
.demo-table-expand {
  font-size: 0;
}
.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}
.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
</style>

<script>
export default {
  data() {
    return {
      vehicleList: {},
      pageSize: 5,
      currentPage: 1,
      ids: [],
      keyWord: "",
    };
  },
  methods: {
    localData() {
      this.$axios
        .get("/selAllVehicle", {
          params: {
            currentPage: this.currentPage,
            pageSize: this.pageSize,
          },
        })
        .then((res) => {
          this.vehicleList = res.data.data;
        })
        .catch((error) => {});
    },
    selConditionVehicle() {
      this.$axios
        .get("/selConditionVehicle", {
          params: {
            keyWord: this.keyWord,
            currentPage: this.currentPage,
            pageSize: this.pageSize,
          },
        })
        .then((res) => {
          this.vehicleList = res.data.data;
        })
        .catch((error) => {});
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.currentPage = 1;
      if (this.keyWord == "") {
        this.localData();
      } else {
        this.selConditionVehicle();
      }
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      if (this.keyWord == "") {
        this.localData();
      } else {
        this.selConditionVehicle();
      }
    },
    handleSelectionChange(val) {
      var ids = []; //存放选中的id
      for (let item of val) {
        ids.push(item.stall_id);
      }
      //将选中的所有项的id放到数据模型中
      this.ids = ids;

      console.log(ids);
      //this.multipleSelection = val;
    },
  },
  mounted() {
    this.localData();
  },
};
</script>